package com.ruoyi.common.utils.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;

import java.io.InputStream;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: OSSUtil
 * @date 2024/7/26 20:37
 */

public class OSSUtil {
    // Endpoint以华东1（杭州）为例，其它Region请按实际情况填写。
    private static final String endpoint = "oss-cn-wulanchabu.aliyuncs.com";
    // 填写Bucket名称，例如examplebucket。
    private static final String bucketName = "dookle";
    private static final String accessKeyId = "LTAI5tB5ZAVTZAB4tRyw8ghr";
    private static final String accessKeySecret = "rI2N4AAYJwryCR4RwJhBkPE6dkNgrP";

    // 填写Object完整路径，完整路径中不能包含Bucket名称，例如exampledir/exampleobject.txt。
    private static String objectName = "image/";
    public static String upload(String fileName, InputStream inputStream){
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId,accessKeySecret);
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName+fileName, inputStream);
        PutObjectResult result = ossClient.putObject(putObjectRequest);
        ossClient.shutdown();
        return "https://dookle.oss-cn-wulanchabu.aliyuncs.com/"+objectName+fileName;
    }

}
